home *** CD-ROM | disk | FTP | other *** search
- /*
- File: InfoPageAspect.c
-
- Contains: Code resource : this code managed AOCE drag commands.
- When a record A is dragged on a record B, this code updates record A to store as an attribute
- an alias to record B and it updates record B to store an alias of record A.
- These aliases are displayed in sublists.
-
- Written by: Christine Buttin - Apple Computer France
-
- Copyright: © 1994 by Apple Computer, Inc.
-
- */
-
- #include <OCE.h>
- #include <OCETemplates.h>
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Packages.h>
- #include <events.h>
- #include <files.h>
- #include <aliases.h>
- #include <errors.h>
- #include <Stdio.h>
- #include <Strings.h>
- #include <String.h>
- #include <Processes.h>
- #include <AERegistry.h>
- #include <OCEErrors.h>
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- #ifndef __OCEAUTHDIR__
- #include <OCEAuthDir.h>
- #endif
-
- #define prChangeRec kDETFirstDevProperty
-
- OSErr DoCommand(DETCallBlock* callBlockPtr);
- OSErr DoDropQuery(DETCallBlock* callBlockPtr);
- OSErr DoAddRecord(DETCallBlock* callBlockPtr);
- void AddRecordAsAttribute (LocalIdentity userLocald,PackedDSSpec* theDSSpec,RecordIDPtr updatedRecord,short refNum,Ptr attrType);
-
- // Entry point called by the CE
- pascal OSErr KeywordsIP(DETCallBlock* callBlockPtr)
- {
- OSErr err = noErr;
-
- if (callBlockPtr->protoCall.target.selector == kDETSelf)
- switch (callBlockPtr->protoCall.reqFunction) {
- case kDETcmdInit:
- // call-for masks
- callBlockPtr->init.newCallFors = kDETCallForCommands + kDETCallForDrops + kDETCallForAttributes;
- break;
-
- case kDETcmdDropQuery:
- err = DoDropQuery(callBlockPtr);
- break;
-
- case kDETcmdPropertyCommand :
- err = DoCommand(callBlockPtr);
- break;
-
- default:
- err=kDETDidNotHandle;
- break;
- }
- else err=kDETDidNotHandle;
-
- return err;
-
- }
-
- /* Called when an object is dropped onto a record.
- Just setup a property number (prChangeRec)
- to be sent to the target aspect.*/
- OSErr DoDropQuery(DETCallBlock* callBlockPtr)
- {
- /* check what is the best guess of the CE regarding the dropped object */
- if (((DETDropQueryBlock*)callBlockPtr)->commandID == kDETAlias) { /* make an alias of the dragged object */
- ((DETDropQueryBlock*)callBlockPtr)->copyToHFS = false;
- ((DETDropQueryBlock*)callBlockPtr)->commandID = prChangeRec;
- return noErr;
- }
- else
- //((DETDropQueryBlock*)callBlockPtr)->commandID = kDETDoNothing;
- return kDETDidNotHandle;
- }
-
-
- /* Called when the CE sends a property command.
- We check it's the property we expect. */
- OSErr DoCommand(DETCallBlock* callBlockPtr)
- {
- OSErr err = noErr;
-
- /* check if called for the prChangeRec command */
- switch(((DETPropertyCommandBlock*)callBlockPtr)->property)
- {
- case prChangeRec :
- err = DoAddRecord(callBlockPtr);
- break;
- default :
- return kDETDidNotHandle;
- break;
- }
- return err;
- }
-
- /* This function adds an attribute as a DSSpec to a record */
- void AddRecordAsAttribute(LocalIdentity userLocald,PackedDSSpec* theDSSpec,RecordIDPtr updatedRecord,short refNum,Ptr attrType)
- {
- OSErr err;
- Attribute theAttribute;
- DirParamBlock dspb;
- AttributeType kwRType;
-
- /* prepare the attribute, set up its type and the date within the attribute */
- OCECToRString (attrType,smRoman,(RString *) &kwRType,kAttributeTypeMaxBytes);
- theAttribute.attributeType = kwRType;
- theAttribute.value.tag = typePackedDSSpec;
- theAttribute.value.dataLength = theDSSpec->dataLength+sizeof(theDSSpec->dataLength);
- theAttribute.value.bytes = (Ptr) theDSSpec;
-
- /* prepare the parameter block used by the Catalog Manager to add an attribut*/
- dspb.addAttributeValuePB.ioCompletion = nil;
- *(long *)&dspb.addAttributeValuePB.serverHint = nil;
- dspb.addAttributeValuePB.dsRefNum = refNum; /* refnum of a personal catalog */
- dspb.addAttributeValuePB.identity = userLocald;
- dspb.addAttributeValuePB.aRecord = updatedRecord; /* record to be modified */
- dspb.addAttributeValuePB.attr = &theAttribute; /* attribute to be added */
- dspb.addAttributeValuePB.clientData = 0;
- err = DirAddAttributeValue (&dspb,false);
- }
-
- /* When a record A is dragged on a record B, this function updates record A to store
- an alias to record B and it updates record B to store an alias of record A.
- Updates occur if records are of the required type. */
- OSErr DoAddRecord(DETCallBlock* callBlockPtr)
- {
- DETCallBackBlock cbb,cbb1,cbb2;
- short PABrefNum;
- RecordID targetRID,receivedRID;
- LocalIdentity userLocalId;
- PackedDSSpec *targetDSSpec,*droppedDSSpec;
- DSSpec dsp,dsp1;
- OSErr err;
- long count,i;
- Str255 targetAttrType;
- Str255 droppedAttrType;
-
- #ifdef USER
- Str255 theStr = "ACFC Keywords";
- RString recType;
- OCECToRString(theStr, smRoman, &recType,kRStringMaxBytes);
- #endif
-
- /* find out target record dsspec */
- cbb.getDSSpec.target.selector = kDETSelf;
- cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
- err = CallBackDET(callBlockPtr, &cbb);
- if (err != noErr)
- return err;
-
- HLock((Handle)cbb.getDSSpec.dsSpec);
- targetDSSpec = *(cbb.getDSSpec.dsSpec);
- /* get record ID */
- PABrefNum = cbb.getDSSpec.refNum;
- userLocalId = cbb.getDSSpec.identity;
- OCEUnpackDSSpec (targetDSSpec,&dsp,&targetRID);
-
- /* find out how many records have been dropped */
- cbb1.getCommandSelectionCount.reqFunction = kDETcmdGetCommandSelectionCount;
- err = CallBackDET(callBlockPtr, &cbb1);
- if (err != noErr) {
- HUnlock((Handle) cbb.getDSSpec.dsSpec);
- DisposeHandle ((Handle) cbb.getDSSpec.dsSpec);
- return err;
- }
-
- count = cbb1.getCommandSelectionCount.count;
-
- for (i = 1; i <= count;i++) {
- /* get the dsspec of dropped record */
- cbb1.getCommandItemN.reqFunction = kDETcmdGetCommandItemN;
- cbb1.getCommandItemN.itemNumber = i;
- cbb1.getCommandItemN.itemType = kDETDSType;
- err = CallBackDET(callBlockPtr, &cbb1);
- if (err == noErr) {
- HLock((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
- droppedDSSpec = *(cbb1.getCommandItemN.item.ds.dsSpec);
- OCEUnpackDSSpec (droppedDSSpec,&dsp1,&receivedRID);
- /* check type of record */
- #ifdef USER
- if (OCEEqualRString (receivedRID.local.recordType, &recType, kOCERecordType)) {
- strcpy(targetAttrType,kMemberAttrTypeBody);
- strcpy(droppedAttrType,"ACFC Alias keyword");
- #else
- if (OCEEqualRString (receivedRID.local.recordType, OCEGetIndRecordType(kUserRecTypeNum), kOCERecordType)) {
- strcpy(targetAttrType,"ACFC Alias keyword");
- strcpy(droppedAttrType,kMemberAttrTypeBody);
- #endif
- /* update the target record to set up the dropped record as an attribute of this record */
- AddRecordAsAttribute (userLocalId,droppedDSSpec,&targetRID,PABrefNum,droppedAttrType);
- /* update the dropped record to set up the target record as an attribute of the dropped record */
- AddRecordAsAttribute (userLocalId,targetDSSpec,&receivedRID,PABrefNum,targetAttrType);
- }
- HUnlock((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
- DisposeHandle((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
- }
- else
- break;
- }
-
- if (err == noErr) {
- /* Ask for immediate update */
- cbb2.requestSync.target = ((DETPropertyCommandBlock*)callBlockPtr)->target;
- cbb2.requestSync.reqFunction = kDETcmdRequestSync;
- err = CallBackDET(callBlockPtr, &cbb2);
- }
- HUnlock((Handle) cbb.getDSSpec.dsSpec);
- DisposeHandle ((Handle) cbb.getDSSpec.dsSpec);
- return err;
-
- }
-
-